package com.algorithm.code.queue;

/**
 * @description TODO
 * @program: sudy
 * @author: kukuxiahuni
 * @create: 2020-01-25 17:40
 **/
public class ArrayQueue<T> implements BaseQueue<T> {

    private final int capacity = 10;
    private T[] queue;
    /**
     * 头出尾进
     */
    private int head = 0, tail = 0;

    @Override
    public T peek() {
        if (head == tail) {
            //为空
            return null;
        }


        return this.queue[head];
    }

    @Override
    public T poll() {
        if (head == tail) {
            return null;
        }
        T val = this.queue[head];
        this.queue = null;
        ++head;
        return val;
    }

    @Override
    public void push(T val) {

        if (val == null) {
            return;
        }
        if (tail == this.queue.length - 1) {
            return;
        }
        this.queue[tail] = val;
        ++tail;
    }
}
